package com.hst.capacity.application.jpush.model.request;


import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Setter
public class JPushPlatform {

    private boolean isAll = false;
    private boolean pushAndroid = false;
    private boolean pushApple = false;
    private boolean pushQuickApp = false;


    public JSONObject getParam() {
        JSONObject jsonObject = new JSONObject();
        if (isAll){
            jsonObject.put("platform","all");
        } else {
            List<String> platformList=new ArrayList<>();
            if(pushAndroid){
                platformList.add("android");
            }
            if(pushApple){
                platformList.add("ios");
            }
            if(pushQuickApp){
                platformList.add("quickapp");
            }
            if(platformList.isEmpty()){
                return null;
            }else{
                JSONArray jsonArray=new JSONArray();
                platformList.stream().forEach(jsonArray::add);

                jsonObject.put("platform",jsonArray);
            }
        }
        return jsonObject;
    }

}
